package com.ktwlsoft.archivemanage.controller.guiBusiness;

import com.ktwlsoft.archivemanage.domain.business.businessService.guiBusiness.GuiGuidanceMendListService;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import com.ktwlsoft.archivemanage.payload.guiBusiness.MendListCommitRequest;
import com.ktwlsoft.archivemanage.payload.mendList.NotifySetRequest;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 指导整改控制器
 *
 * @author zhuhe on 2020/4/29 9:43
 * @version 1.0
 */
@Api(value = "指导整改控制器", description = "指导整改控制器")
@RestController
@RequestMapping("guiGuidanceMendList")
public class GuiGuidanceMendListController {

    /**指导整改*/
    private final GuiGuidanceMendListService mendListService;

    public GuiGuidanceMendListController(GuiGuidanceMendListService mendListService) {
        this.mendListService = mendListService;
    }

    @ApiOperation("管理web-列表")
    @ResponseBody
    @GetMapping("manageWebFindPage")
    @UserAuthenticate(actionCode = "GUIGUIDANCEMENDLIST_PAGE")
    public ResponseEntity<?> manageWebFindPage(@RequestParam(defaultValue = "1") int pn,
                                               @RequestParam(defaultValue = "30") int pageSize,
                                               @ApiParam(name = "mendState", value = "整改状态:1待整改, 2待验证, 3打回待整改, 4验证通过") @RequestParam(defaultValue = "") Integer mendState,
                                               @ApiParam(name = "guidanceTimeStart", value = "指导时间开始") @RequestParam(defaultValue = "") String guidanceTimeStart,
                                               @ApiParam(name = "guidanceTimeEnd", value = "指导时间结束") @RequestParam(defaultValue = "") String guidanceTimeEnd,
                                               @ApiParam(name = "keywords", value = "关键字") @RequestParam(defaultValue = "") String keywords) {
        return ResponseEntity.ok(mendListService.findPage(pn,pageSize,mendState,guidanceTimeStart,guidanceTimeEnd,keywords,"manageWeb"));
    }

    @ApiOperation("管理web-详情")
    @ResponseBody
    @GetMapping("getDetails")
    public ResponseEntity<?> getDetails(@ApiParam(name = "id", value = "整改id") @RequestParam Long id) {
        return ResponseEntity.ok(mendListService.getDetails(id));
    }

    @ApiOperation("管理web-下达整改单")
    @ResponseBody
    @GetMapping("addMendList")
    public ResponseEntity<?> addMendList(@ApiParam(name = "id", value = "业务指导id") @RequestParam Long id) {
        return ResponseEntity.ok(mendListService.addMendList(id));
    }

    @ApiOperation("管理web-验证")
    @ResponseBody
    @GetMapping("verify")
    @UserAuthenticate(actionCode = "GUIGUIDANCEMENDLIST_VERIFY")
    public ResponseEntity<?> verify(@ApiParam(name = "id", value = "整改id") @RequestParam Long id,
                                    @ApiParam(name = "verifyRemark", value = "验证备注") @RequestParam(defaultValue = "") String verifyRemark,
                                    @ApiParam(name = "ispass", value = "是否通过:true通过,false不通过") @RequestParam(defaultValue = "") Boolean ispass) {
        return ResponseEntity.ok(mendListService.verify(id,verifyRemark,ispass));
    }

    @ApiOperation("管理web-消息通知设置")
    @ResponseBody
    @PostMapping("setMendList")
    @UserAuthenticate(actionCode = "GUIGUIDANCEMENDLIST_SET")
    public ResponseEntity<?> setMendList(@RequestBody NotifySetRequest request) {
        return ResponseEntity.ok(mendListService.setNotifySet(request));
    }

    @ApiOperation("管理web-操作日志")
    @ResponseBody
    @GetMapping("operationLog")
    @UserAuthenticate(actionCode = "GUIDANCEMENDLIST_OPERATIONLOG")
    public ResponseEntity<?> operationLog(@RequestParam(defaultValue = "1") int pn,
                                         @RequestParam(defaultValue = "30") int pageSize,
                                         @ApiParam(name = "guiMendId", value = "指导整改id") @RequestParam Long guiMendId) {
        return ResponseEntity.ok(mendListService.operationLog(pn,pageSize,guiMendId));
    }

    @ApiOperation("用户web-整改提交")
    @ResponseBody
    @PostMapping("mendListCommit")
    public ResponseEntity<?> mendListCommit(@Valid @RequestBody MendListCommitRequest request,BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResponseEntity.ok(Result.body(request, ResultType.CHECK_ERROR).withMessage(bindingResult.getFieldError().getDefaultMessage()));
        }
        return ResponseEntity.ok(mendListService.mendListCommit(request));
    }

    @ApiOperation("用户web-列表")
    @ResponseBody
    @GetMapping("userWebFindPage")
    public ResponseEntity<?> userWebFindPage(@RequestParam(defaultValue = "1") int pn,
                                               @RequestParam(defaultValue = "30") int pageSize,
                                               @ApiParam(name = "mendState", value = "整改状态:1待整改, 2待验证, 3打回待整改, 4验证通过") @RequestParam(defaultValue = "") Integer mendState,
                                               @ApiParam(name = "guidanceTimeStart", value = "指导时间开始") @RequestParam(defaultValue = "") String guidanceTimeStart,
                                               @ApiParam(name = "guidanceTimeEnd", value = "指导时间结束") @RequestParam(defaultValue = "") String guidanceTimeEnd,
                                               @ApiParam(name = "keywords", value = "关键字") @RequestParam(defaultValue = "") String keywords) {
        return ResponseEntity.ok(mendListService.findPage(pn,pageSize,mendState,guidanceTimeStart,guidanceTimeEnd,keywords,"userWeb"));
    }

    @ApiOperation("用户web-详情")
    @ResponseBody
    @GetMapping("userGetDetails")
    public ResponseEntity<?> userGetDetails(@ApiParam(name = "id", value = "整改id") @RequestParam Long id) {
        return ResponseEntity.ok(mendListService.getDetails(id));
    }
}